<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>修改</title>
        <script src="js/jquery-3.3.1.js"></script>
        <script>
            $(function () {
                //1.//从url中获取id
                var search = location.search;
                var id = search.split("=")[1];


                //自动获取user数据
                $.post("user/selectUser", {id,id}, function (info) {
                    if(info.flag){
                        var user = info.data;

                        $("#id").val(user.id);
                        $("#username").val(user.username);
                        $("#password").val(user.password);
                        $("#email").val(user.email);

                        //性别~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        var sex = user.sex;
                        if(sex=="男"){
                            $("#divn").html('<input type="radio" name="sex" value="男" checked>男 <input type="radio" name="sex" value="女">女')
                        }else{
                            $("#divn").html('<input type="radio" name="sex" value="男" >男 <input type="radio" name="sex" value="女" checked>女')
                        }

                        //爱好~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        var loves = user.love;

                        for (let i = 0; i < loves.length; i++) {
                            var id = loves[i].id;
                            if(id == "1"){
                                $("#lq").prop("checked",true);
                            }else if(id == "2"){
                                $("#pp").prop("checked",true);
                            }else if(id =="3"){
                                $("#ym").prop("checked",true);
                            }
                        }
                    }
                });


            });
        </script>
    </head>
    <body>
        <h3>修改用户</h3>
        <form action="user/upUser" method="post" >
            id:<input type="text" name="id" id="id"><br>
            用户名:<input type="text" name="username" id="username"><br>
            密码:<input type="password" name="password" id="password"><br>
            email:<input type="text" name="email" id="email"><br>
            性别:
            <div id="divn"></div>
            爱好:
            <input type="checkbox" name="love" value="1" id="lq">篮球
            <input type="checkbox" name="love" value="2" id="pp">乒乓球
            <input type="checkbox" name="love" value="3" id="ym">羽毛球<br>

            <input type="submit" value="修改">
        </form>
    </body>
</html>



